#!/bin/bash
SCRIPT_BASE_DIR=$( dirname "${BASH_SOURCE[0]}" )
source "${SCRIPT_BASE_DIR}/common/fs_utils.sh"

set -e

function usage() {
    echo "Usage: $( basename $0 ) [-h | -1 | -2 | -m <module_name>]"
    echo "    调用ara-cli CreatePlatformContainers编译eb adg container."
    echo "    注意:带--clean-sysroot --build参数，编译时间较长"
    echo "    参数:"
    echo "      -1: 为示例1建造container"
    echo "      -2: 为示例2建造container,默认"
    echo "      -m: 快速编译某个模块--<lsp|psp|dlt|com|tsyn|dm|em|pm|phm|ucm|nm|dlt-daemon|iam|sm|socom|cryptoapi>"
    echo "      -h: 输出本信息"

    exit 1
}   


instance=2
while getopts ":h12m:" args
do
    case "$args" in
    1)
        instance=1
        ;;
    2)
        instance=2
        ;;
    m)
        mod=${OPTARG}
        ;;
    *)
        usage
        ;;
    esac
done

if [ -z "$instance" ]
then
    usage
fi

if [ -z "${mod}" ]
then
    cmd_opts="--clean-sysroot --build "
else
    cmd_opts="--module ${mod} --build "
fi

dir_exists_or_die ara_Com

buildType=RelWithDebInfo

cmd="ara-cli CreatePlatformContainers --cpus 16 --build-type ${buildType} ${cmd_opts} --target-platform qemu-x86 --instance ${instance}"
read -p "执行命令: ${cmd} ?<Y/N>" ans

if [ "y" == "${ans}" -o "Y" == "${ans}" ]
then
   ${cmd} 
fi
